package com.example.config;

import com.google.code.kaptcha.Constants;
import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;


 /**
  * 验证码图片参数配置
  *  @Author: 常占
  *  @Date: 2020/9/10 21:45
  *  @Description:
  */

@Configuration
public class KaptchaConfig {

    @Bean
    public DefaultKaptcha defaultKaptcha(){

        DefaultKaptcha kaptcha = new DefaultKaptcha();
        Properties properties = new Properties();
        properties.setProperty(Constants.KAPTCHA_BORDER,"no");//边框
        properties.setProperty(Constants.KAPTCHA_BORDER_COLOR,"255,255,255");//颜色
        properties.setProperty(Constants.KAPTCHA_IMAGE_WIDTH,"100");//宽度
        properties.setProperty(Constants.KAPTCHA_IMAGE_HEIGHT,"30");//高度
        properties.setProperty(Constants.KAPTCHA_TEXTPRODUCER_CHAR_STRING,"1234567890");//验证码字符集
        properties.setProperty(Constants.KAPTCHA_TEXTPRODUCER_FONT_SIZE,"25");//字体大小
        properties.setProperty(Constants.KAPTCHA_TEXTPRODUCER_CHAR_SPACE,"3");//字体间隔
        properties.setProperty(Constants.KAPTCHA_TEXTPRODUCER_FONT_COLOR,"blue");//字体颜色
        properties.setProperty(Constants.KAPTCHA_TEXTPRODUCER_CHAR_LENGTH,"5");
        properties.setProperty(Constants.KAPTCHA_TEXTPRODUCER_FONT_NAMES,"Arial,Courier");//字体名字
        properties.setProperty(Constants.KAPTCHA_NOISE_COLOR,"200,200,200");//干扰线颜色
        properties.setProperty(Constants.KAPTCHA_BACKGROUND_CLR_FROM,"white");//背景渐变色
        properties.setProperty(Constants.KAPTCHA_BACKGROUND_CLR_TO,"white");
        properties.setProperty(Constants.KAPTCHA_OBSCURIFICATOR_IMPL,"com.google.code.kaptcha.impl.ShadowGimpy");//图片实现类

        //kaptcha
        Config config= new Config(properties);
        kaptcha.setConfig(config);

        return kaptcha;

    }

}
